package com.lagou.bootPro.web;

import com.lagou.bootPro.context.MyApplicationContext;
import com.lagou.bootPro.registration.MyServletContextInitializer;

import javax.servlet.ServletContainerInitializer;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import java.util.Map;
import java.util.Set;

/**
 * @ClassName MySpringServletContainerInitializer
 * @Description
 * @Author playboy
 * @Date 2021/5/15 4:17 下午
 * @Version 1.0
 **/
public class MySpringServletContainerInitializer implements ServletContainerInitializer {

	private MyApplicationContext myApplicationContext;

	public MySpringServletContainerInitializer(MyApplicationContext myApplicationContext) {
		this.myApplicationContext = myApplicationContext;
	}

	@Override
	public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
		Map<String, MyServletContextInitializer> initializers = myApplicationContext.getBeansOfType(MyServletContextInitializer.class);
		for (Map.Entry<String, MyServletContextInitializer> entry : initializers.entrySet()) {
			MyServletContextInitializer value = entry.getValue();
			value.onStartup(ctx);
		}
	}
}
